package com.samoiloff.framework.model {
import flash.events.Event;
import flash.events.EventDispatcher;

/**
	 * Dispatched when <code>complete()</code> method is called. This serves as sygnal that <b>Model</b>
	 * is initialized. Immidiately after this event dispatched the <b>View</b> instantiates automatically.
	 * 
	 * @eventType flash.events.Event.COMPLETE
	 */ 

	[Event(name="complete", type= "flash.events.Event.COMPLETE")]

	/**
	 * AbstractModel should not be instantiated, it should be inherited.
	 * Model contains all relevant data, that completely (explicitly) describes component state.
	 * Every user-defined property of Model should have setter. In setter
	 * the last line should be <code>dispatchEvent(new Event(PROPERTY_NAME_CHANGED))</code>
	 * where <code>PROPERTY_NAME</code> is the name of property that corresponds
	 * to the setter. Through this events View observes changes in Model and can
	 * be updated correspondingly.  
	 * 
	 * 
	 * @author Samoiloff (http://blog.samoiloff.com)
	 * 
	 * @example
	 * Simple example of observable property definition in Model.
	 * 
	 * <listing version="3.0">
	 * public static const PROP1_CHANGED:String = "prop1_changed";
	 * 
	 * private var _prop1:String;
	 * 
	 * public function get prop1():String {
	 *     return _prop1;
	 * }
	 * 
	 * public function set prop1(value:String):void {
	 *     _prop1 = value;
	 *     dispatchEvent(new Event(PROP1_CHANGED));
	 * }
	 * </listing>
	 */
	public class AbstractModel extends EventDispatcher {
		
		/**
		 * Constructor.
		 */


		public function AbstractModel() {

		}

		private var _ready : Boolean;

		/**
		 * This function should be called in subclass of <code>AbstractModel</code>. Call this function
		 * when model is initialized. As a result the <b>Model</b> dispatches <code>Event.COMPLETE</code>.
		 * Thus <b>View</b> can be initialized.
		 */
		
		protected function complete():void {
			_ready = true;
			dispatchEvent(new Event(Event.COMPLETE));
		}
		
		/**
		 * <b>View</b> automatically checks this property in the case <b>Model</b> initialized
		 * before <b>View</b> is subscribed for <b>Model</b> events. You can use this property to check
		 * wether <b>Model</b> is initialized.
		 */
		
		public function get ready() : Boolean {
			return _ready;
		}
		
		public function destroy():void {

		}

	}
	
	
}
